<?php
/*
 * Created on 07.03.2007
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

class TardoView {

	private $filenames;

	public function __construct($range = 0) {

		$this->filenames[] = "com/tardo/data/tardo_".date('Ym').".xml";

		for($i = 1; $i<$range;$i++) {
			$month = date('m')-$i;
			if($month<10) {
				$this->filenames[] = "com/tardo/data/tardo_".date('Y').'0'.$month.".xml";
			} else {
				$this->filenames[] = "com/tardo/data/tardo_".date('Y').'0'.$month.".xml";
			}
		}

		$this->load_datas();
	}

	private function load_datas() {
		$browsers = array();
		$i = 0;
		foreach($this->filenames as $filename) {
				try {
				$xml = XML::load($filename);

				foreach($xml->day as $day) {
					foreach($day->operationSystems->os as $os) {
						foreach($os->browser as $browser) {

							$nameversion = explode("v:", $browser['name']);
							$browsers[$i][$nameversion['0']] = $nameversion['1'];
							$browsers[$i]['count'] = (string)$browser['count'];
							$i++;
						}
					}
				}

			} catch(FileNotFoundException $e) {
				// no data to load
				echo "nix";
			}
		}
		echo "<pre>";
				print_r($browsers);
				echo "</pre>";
	}
}
?>
